package com.cxs.shopstore.utils;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collection;

/*
 * @Author:cxs
 * @Date:2021/5/10  18:13
 * @Version 1.0
 * 前段传递的array转换list集合
 * */
@Component
public class CollectionUtils {
    public Collection<String> arrayToColl(String [] array){
        Collection<String> list = new ArrayList<>();
        String item = "";
        if(array.length == 1){
            item = array[0].replaceAll("\"", "");
            item = item.replaceAll("\\]","");
            item = item.replaceAll("\\[","");
            list.add(item);
        }else{
            for (int i = 0; i < array.length; i++) {
                if(i==0){
                    item = array[i].replaceAll("\"", "");
                    item = item.replaceAll("\\[","");
                }else if(i == array.length - 1){
                    item = array[i].replaceAll("\"", "");
                    item = item.replaceAll("\\]","");
                }else{
                    item = array[i].replaceAll("\"", "");
                }
                list.add(item);
            }
        }
        return list;
    }
}
